package com.itheima.fastJson;

import com.alibaba.fastjson.JSON;
import com.itheima.pojo.User;
import org.junit.Test;

import java.util.ArrayList;

public class FastJsonDemo {
    @Test
    public void method01(){
        User user = new User("zs", "123");
        System.out.println(user.toJson());
    }

    public  void method02(){
        User user = new User("ss", "123");
        String s= JSON.toJSONString(user);
        System.out.println(s);
    }
@Test
    public void method03(){
        //java集合转json格式字符串
        User user1 = new User("ls", "123");
        User user2 = new User("ww", "110");

        ArrayList<User> list = new ArrayList<>();
        list.add(user1);
        list.add(user2);
        String s = JSON.toJSONString(list);
        System.out.println(s);
    }
@Test
    public void method04(){
        String json="";

        User user=JSON.parseObject(json,User.class);
        System.out.println(json);
    }
}